<template>
    <div v-loading="loading" class="box">
        <div v-if="done">
            <h1>欢迎使用</h1>
            <div>感谢安装，<a href="/" style="color: #999;font-weight: 600;letter-spacing:2px">点击进入首页</a>.</div>
        </div>
        <div v-else>
            <el-button @click="importSQL()">导入数据</el-button>
        </div>
    </div>
</template>

<script>
    export default {
        name:"step_",
        methods:{
            next(){
                this.$router.app.$emit("step",1)
            },
            importSQL(){
                this.loading = true;
                this.$http.get(this.$_URL,{
                    params:{do:'Import'}
                }).then((res)=> {
                    this.loading = false;
                    if(res.body.error){
                        this.$message.error(res.body.error);
                        return
                    }
                    if(res.body.result === 'done'){
                        this.$message({
                            message: res.body.message,
                            type: 'success'
                        });
                        this.done = true;
                        this.$router.app.$emit("done")
                        return
                    }
                    this.$message.error("未知错误");
                },()=>{
                    this.loading = false;
                });
            }
        },
        data(){
            return {
                loading:false,
                done:false
            }
        },
        mounted(){
            setTimeout(this.import,1000)
        }
    }
</script>
<style>
    .box{
        height: 300px;
        width: 100%;
        display: flex;
        justify-content: center;align-items: center;
    }
</style>